# -*- coding: utf-8 -*- 
"""
========================================================================================================================
@project : my-sanic
@file: myDecorator
@Author: mengying
@email: 652044581@qq.com
@date: 2023/3/3 11:00
@desc: 装饰器，记录日志时间等
========================================================================================================================
"""
import asyncio
from functools import wraps
from sanic.response import json


# 异步接口装饰器
def asyncInterface(*args):
    def decorator(function):
        @wraps(function)
        async def decorated_function(request, *args, **kwargs):
            response = await function(request, *args, **kwargs)
            return response

        return decorated_function

    return decorator


# 同步接口装饰器
def syncInterface(*args):
    def decorator(function):
        @wraps(function)
        def decorated_function(request, *args, **kwargs):
            print("同步接口装饰器已经生效")

            response = function(request, *args, **kwargs)
            return response

        return decorated_function

    return decorator


# 同步方法装饰器
def syncMethod(function):
    @wraps(function)
    def wrapper(*args, **kwargs):
        result = function(*args, **kwargs)

        return result

    return wrapper


# 异步方法装饰器
def asyncMethod(function):
    @wraps(function)
    async def wrapper(*args, **kwargs):
        result = await function(*args, **kwargs)

        return result

    return wrapper
